<?php
/**
 *
 * @author: xaboy<365615158@qq.com>
 * @day: 2017/12/20
 */

namespace app\models\store;

use app\admin\model\system\ShippingTemplatesFree;
use app\admin\model\system\ShippingTemplatesRegion;
use crmeb\basic\BaseModel;
use think\facade\Cache;
use crmeb\traits\ModelTrait;
use think\facade\Log;
use app\models\system\SystemStore;
use app\models\routine\RoutineTemplate;
use app\models\user\{User, UserAddress, UserBill, UserRecharge, WechatUser};
use crmeb\services\{
    SystemConfigService, WechatTemplateService, workerman\ChannelService
};
use crmeb\repositories\{
    GoodsRepository, PaymentRepositories, OrderRepository, ShortLetterRepositories, UserRepository
};
use app\admin\model\system\ShippingTemplates;

/**
 * TODO 订单Model
 * Class StoreOrder
 * @package app\models\store
 */
class Agent extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'agent_config';

    use ModelTrait;


    /**
     * 充值成为分销商
     */
    public static function setLevelComplete($rechargeId){
        //充值信息
        $recharge_info = UserRecharge::get(['id'=>$rechargeId]);
        //代理配置信息
        $proxy_info    = Agent::get(['mer_id'=>$recharge_info['mer_id']]);
        //用户信息
        $user_info     = User::get(['uid'=>$recharge_info['uid']]);
        //累计充值
        $recharge_total = UserRecharge::where('uid',$recharge_info['uid'])->sum('price');
        $res = true;
        if($user_info['is_promoter']==1){
            return $res;
        }
        if($recharge_total>=$proxy_info['one_recharge']){
            User::update(['is_promoter'=>1],['uid'=>$recharge_info['uid']]);
        }
        return $res;

    }



}